/*
 * VideoCaptureSource.cpp
 *
 *  Created on: 2018年3月19日
 *      Author: zhengboyuan
 */

#include "VideoCaptureSource.h"

VideoCaptureSource::VideoCaptureSource(int cameraId):
	m_size(640, 480),
	m_cameraId(cameraId),
	m_capture(cameraId)
{
}

VideoCaptureSource::~VideoCaptureSource()
{
}


void VideoCaptureSource::setSize(const cv::Size& size)
{
	if (size.width > 0 && size.height > 0)
	{
		m_size = size;
		
		m_capture.set(cv::CAP_PROP_FRAME_WIDTH, m_size.width);
		m_capture.set(cv::CAP_PROP_FRAME_HEIGHT, m_size.height);

		m_size.width = (int)m_capture.get(cv::CAP_PROP_FRAME_WIDTH);
		m_size.height = (int)m_capture.get(cv::CAP_PROP_FRAME_HEIGHT);
	}
}

cv::Size VideoCaptureSource::getSize()
{
	return m_size;
}

bool VideoCaptureSource::getFrame(cv::Mat& frame)
{
	m_capture >> frame;
	return !frame.empty();
}

bool VideoCaptureSource::isOpened()
{
	return m_capture.isOpened();
}